package com.kgc.activityprovider.service.impl;

import com.kgc.activiti.util.ResponseMsg;
import com.kgc.activityprovider.dao.ProduceMapper;
import com.kgc.activityprovider.feign.store.ProMoveFeign;
import com.kgc.activityprovider.service.WorkFlowUtilService;
import com.kgc.store.pojo.ProDivide;
import com.kgc.store.pojo.ProMove;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PromoveWorkFlowServiceImpl implements WorkFlowUtilService {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ProMoveFeign proMoveFeign;
    @Autowired
    private ProduceMapper produceMapper;

    @Override
    public ResponseMsg changeStatus(String code, int status) {
        logger.info("PromoveWorkFlowServiceImpl.changeStatus code:{},status:{}", code, status);
        ResponseMsg responseMsg = new ResponseMsg();
        int count = produceMapper.changePromove(code,status);
        if (count > 0) {
            try {
                ProMove proMove = (ProMove) proMoveFeign.getOne(code).getData();
                if (status == 3) {
                    String s = proMoveFeign.moveStore(proMove).getCode();
                    if (!"200".equals(s)){
                        responseMsg.setCode("201");
                        return responseMsg;
                    }
                }
            }catch (Exception e){
                logger.error("CostAdjustmentWorkFlowServiceImpl.changeStatus error:{}", e);
            }
            responseMsg.setCode("200");
        }else{
            responseMsg.setCode("201");
        }
        return responseMsg;
    }

    @Override
    public ResponseMsg insertCheck(String code, Integer checkManId, String checkComment) {
        logger.info("PromoveWorkFlowServiceImpl.insertCheck code:{},status:{},checkComment:{}", code, checkManId,checkComment);
        ResponseMsg responseMsg = new ResponseMsg();
        int count = produceMapper.insertCheckPromove(code,checkManId,checkComment);
        logger.debug("ProduceMapper.insertCheckCostAdjustment count:{},count:{}", count, count);
        if (count > 0) {
            responseMsg.setCode("200");
        }else{
            responseMsg.setCode("201");
        }
        return responseMsg;
    }

    @Override
    public ResponseMsg sendEmail(String code, String emailTo) {
        return null;
    }
}
